

// Script function: Analysis of rectangle ROI
// Requirement: Open an images with rectangle ROIs

// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined 
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html



image GlobalSinoImage

if ( !GetFrontImage( GlobalSinoImage ) )
Throw( "Please open an image and draw a rectangle ROI" )
 
GlobalSinoImage:=getfrontimage()

ImageDisplay EMImage=GlobalSinoImage.ImageGetImageDisplay(0)

if( 1 !=  EMImage.ImageDisplayCountROIs())
Throw( "Please draw a rectangle ROI" )

number EMxSize, EMySize, EMxScale, EMyScale
string EMImageName
 
GetSize(GlobalSinoImage, EMxSize, EMySize)
GetScale(GlobalSinoImage, EMxScale, EMyScale)
GetName(GlobalSinoImage, EMImageName)
 
number EMTop, EMLeft, EMBottom, EMRight
number EMROIUnitWidth, EMROIUnitHeight
 
ImageDisplay EMImageDisplay=GlobalSinoImage.ImageGetImageDisplay(0)
ROI EMROI=EMImageDisplay.ImageDisplayGetROI(0)
ROIGetRectangle(EMROI, EMTop, EMLeft, EMBottom, EMRight)
EMROIUnitWidth=(EMRight-EMLeft)*EMxScale
EMROIUnitHeight=(EMBottom-EMTop)*EMyScale
image EMROIImage=GlobalSinoImage[]
ShowImage(EMROIImage)
 
ImageCopyCalibrationFrom(EMROIImage, GlobalSinoImage)
 
ImageDisplay EMROIDisplay=EMROIImage.ImageGetImageDisplay(0)
EMROIDisplay.ApplyDataBar()
string GlobalSinoImageName="ROI from " + EMImageName
SetName(EMROIImage, GlobalSinoImageName)
 
number EMMean = Mean (EMROIImage[])
String EMLengthUnits = GetUnitString(EMROIImage)
String EMIntensityUnits = ImageGetIntensityUnitString(EMROIImage)
 
// Display the results on Output window: It can be copied-and pasted onto excel spread sheet
result ("Results from the selected region: \n")
result ("You can copy and paste the data onto excel \n")
result ("\n Mean intensity of the region " +" \t"+ EMMean +" \t"+ EMIntensityUnits)
result ("\n Sum intensity of the region " +" \t"+ Sum (EMROIImage[]) +" \t"+ EMIntensityUnits)
result ("\n Maximum intensity of the region " +" \t"+ max(EMROIImage[]) +" \t"+ EMIntensityUnits)
result ("\n Minimum intensity of the region " +" \t"+ min(EMROIImage) +" \t"+ EMIntensityUnits)
result ("\n" )
result ("\n Width of the region " +" \t"+ EMROIUnitWidth +" \t"+ EMLengthUnits)
result ("\n Height of the region " +" \t"+ EMROIUnitHeight +" \t"+ EMLengthUnits)
result ("\n Area of the region " +" \t"+ (EMROIUnitWidth*EMROIUnitHeight) +" \t"+ EMLengthUnits)
 
 
// Display the results on a popup window
String GlobalSinoPopupResults = "Results from the selected region: \n"
GlobalSinoPopupResults += "\n Mean intensity of the region: " + EMMean + " ["+ EMIntensityUnits + "]"
GlobalSinoPopupResults += "\n Sum intensity of the region: " + Sum (EMROIImage[]) + " ["+ EMIntensityUnits + "]"
GlobalSinoPopupResults += "\n Maximum intensity of the region: " + max(EMROIImage[]) + " ["+ EMIntensityUnits + "]"
GlobalSinoPopupResults += "\n Minimum intensity of the region: " + min(EMROIImage) + " ["+ EMIntensityUnits + "]"
GlobalSinoPopupResults += "\n"
GlobalSinoPopupResults += "\n Width of the region: " + EMROIUnitWidth + " ["+ EMLengthUnits + "]"
GlobalSinoPopupResults += "\n Height of the region: " + EMROIUnitHeight + " ["+ EMLengthUnits + "]"
GlobalSinoPopupResults += "\n Area of the region: " + (EMROIUnitWidth*EMROIUnitHeight) + " ["+ EMLengthUnits + "^2]"
 
OKDialog (GlobalSinoPopupResults)